//客户端打包 base
const path = require('path');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const HappyPack = require('happypack');
const HappyPackPool = HappyPack.ThreadPool({size: 5});
const CircularDependencyPlugin = require('circular-dependency-plugin');
const webpackBar = require('webpackbar');
module.exports = {
    //避免打包时加入不必要的依赖
    // externals: {
    //     "react": "React",
    //     "react-dom": "ReactDOM"
    // },
    module: {
        rules: [
            {
                test: /\.(png|woff|woff2|svg|eot|jpg)($|\?)/i,
                use: [
                    {
                        loader: 'url-loader',
                        options: {
                            limit: 8192,
                            mimetype:'image/png',
                            name: 'images/[name].[hash:7].[ext]'
                        }
                    }
                ]
            }
        ]
    },
    resolve: {
        //引入依赖时可忽略的后缀名
        extensions: ['.js', '.json', '.jsx','.ts','.tsx'],
        //文件路径替代的一些配置，example：&static在全局使用可引用static这个文件夹
        alias: {
            '&static': path.resolve(__dirname, '../src/static'),
            '&icons': path.resolve(__dirname, '../src/static/icons'),
            '&helpers': path.resolve(__dirname, '../src/helpers'),
            '&images': path.resolve(__dirname, '../src/static/images'),
            '&components': path.resolve(__dirname, '../src/components'),
            '&redux': path.resolve(__dirname, '../src/redux'),
            '&widgets': path.resolve(__dirname, '../src/widgets')
        }
    },
    plugins: [
        new HappyPack({
            id: 'babel',
            threadPool: HappyPackPool,
            // cache: true,
            loaders: ['babel-loader','astroturf/loader']
        }),
        new CleanWebpackPlugin(['dist'],{
            root: path.resolve(__dirname, '..')
        }),
        new CircularDependencyPlugin({
            exclude: /node_modules/,
            failOnError: true,
            allowAsyncCycles: false,
            cwd: path.resolve(__dirname, '..'),
        }),
        new webpackBar(),
    ]
};
